<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>签约客户信息</title>
    <link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="customer_table" lay-filter="test"></table>
        </div>
    </div>
</div>
<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit" th:text="审核"></a>
</script>
<script src="layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'table'], function () {
        var layer = layui.layer, form = layui.form, table = layui.table, $ = layui.$;

        /**
         * cookie操作
         */
        function setCookie(name, value, iDay) {
            var oDate = new Date();
            oDate.setDate(oDate.getDate() + iDay);
            document.cookie = name + '=' + value + ';expires=' + oDate;
        }

        function getCookie(name) {
            var arr = document.cookie.split('; ');
            for (var i = 0; i < arr.length; i++) {
                var arr2 = arr[i].split('=');
                if (trim(arr2[0]) === name) {
                    return unescape(trim(arr2[1]));
                }
            }
            return '';
        }

        function removeCookie(name) {
            setCookie(name, 1, -1);
        }

        function trim(str) {
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }

        function isObjectEmpty(obj) {
            for (var key in obj) {
                if (key) {
                    return false
                }
            }
            return true
        }

        //console.log("用户登录名是:" + getCookie("telphone"));

        Date.prototype.Format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1,//月份
                "d+": this.getDate(),//日
                "H+": this.getHours(),//小时
                "m+": this.getMinutes(),//分
                "s+": this.getSeconds(),//秒
                "q+": Math.floor((this.getMonth() + 3) / 3),//季度
                "S+": this.getMilliseconds()//毫毛
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        };
        table.render({
            elem: '#customer_table'
            , url: 'getdealcustomerinfo/' + getCookie("telphone")
            , cellMinWidth: 80     //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [
                [
                    {
                        title: '序号', templet: function (d) {
                            return d.LAY_TABLE_INDEX + 1
                        }, align: 'center'
                    },
                    {field: 'agentName', title: '经纪人姓名', width: 80, sort: true, align: 'center'},
                    {field: 'sex', title: '性别', width: 80, align: 'center'},
                    {field: 'customerName', title: '客户姓名', width: 80, sort: true, align: 'center'}
                    , {field: 'telphone', title: '电话', align: 'center'}
                    , {field: 'detailAddress', title: '详细地址', align: 'center'}
                    //     , {
                    //     field: 'style', title: '装修类型', templet: function (d) {
                    //         switch (d.style) {
                    //             case 1:
                    //                 return "现代";
                    //                 break;
                    //             case 2:
                    //                 return "欧式";
                    //                 break;
                    //             case 3:
                    //                 return "美式";
                    //                 break;
                    //             case 4:
                    //                 return "中式";
                    //                 break;
                    //             case 5:
                    //                 return "日式";
                    //                 break;
                    //             case 6:
                    //                 return "北欧";
                    //                 break;
                    //             case 7:
                    //                 return "其他";
                    //                 break;
                    //             default:
                    //                 return "暂无"
                    //                 break;
                    //
                    //         }
                    //     }, sort: true, align: 'center'
                    // }
                    //     , {
                    //     field: 'scheme', title: '装修方案', templet: function (d) {
                    //         switch (d.scheme) {
                    //             case 1:
                    //                 return "全包";
                    //                 break;
                    //             case 2:
                    //                 return "半包";
                    //                 break;
                    //             case 3:
                    //                 return "其他";
                    //                 break;
                    //             default:
                    //                 return "暂无"
                    //                 break;
                    //         }
                    //     }, sort: true, align: 'center'
                    // }
                    , {
                    field: 'recomDatetime', title: '推荐时间', templet: function (d) {
                        return new Date(new Date(d.recomDatetime).toString()).Format("yyyy-MM-dd");
                    }, align: 'center'
                }
                    , {
                    field: 'verifyStatus', title: '客户状态', templet: function (d) {
                        //1待审核2期房3暂时不装4已量房5已进店6跟踪中7已交定金8已签合同9无效客户
                        switch (d.verifyStatus) {
                            case 1:
                                return "待审核";
                                break;
                            case 2:
                                return "期房";
                                break;
                            case 3:
                                return "暂时不装";
                                break;
                            case 4:
                                return "已量房";
                                break;
                            case 5:
                                return "已进店";
                                break;
                            case 6:
                                return "跟踪中";
                                break;
                            case 7:
                                return "已交定金";
                                break;
                            case 8:
                                return "已签合同";
                                break;
                            case 9:
                                return "无效客户";
                                break;
                            default:
                                return "暂无状态"
                                break;
                        }
                    }, sort: true, align: 'center'
                }
                    , {fixed: 'right', title: '操作', toolbar: '#bar', width: 150}
                ]
            ]
            , page: true
        });

        //判断浏览器大小方法
        function screen() {
            //获取当前窗口的宽度
            var width = $(window).width();
            if (width > 1200) {
                return 3;   //大屏幕
            } else if (width > 992) {
                return 2;   //中屏幕
            } else if (width > 768) {
                return 1;   //小屏幕
            } else {
                return 0;   //超小屏幕
            }
        }

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {

            }
            ;
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    title: "修改客户状态",
                    name: 'modifycustomer',
                    anim: 1,
                    resize: false,
                    offset: 'auto',
                    content: 'modifycuststatus?id=' + data.id,
                    area: screen() < 2 ? ['90%', '80%'] : ['500px', '300px'],
                    end: function () {
                        location.reload();
                    }
                });
            }
        });
    });
</script>
</body>
</html>